package jgl.vajra.kingkong.part.vehicle.viewModel;

import com.orhanobut.logger.Logger;

import java.util.List;
import java.util.Map;

import jgl.vajra.kingkong.bean.AdditionalRequirementsBean;
import jgl.vajra.kingkong.bean.CouponAvailableBean;
import jgl.vajra.kingkong.bean.MarketPriceBean;
import jgl.vajra.kingkong.part.vehicle.contract.ConfirmOrderContract;
import jgl.vajra.kingkong.part.vehicle.model.ConfirmOrderModel;
import jgl.vajra.kingkong.widget.mvvm.factory.CreateModel;
import jgl.vajra.kingkong.widget.retrofithelper.rxsubscriber.ProgressObserver;

@CreateModel(ConfirmOrderModel.class)
public class ConfirmOrderViewModel extends ConfirmOrderContract.ViewModel{

    @Override
    public void getRandomOrderNumber() {
        mModel.getRandomOrderNumber().subscribe(new ProgressObserver<String>(false, null) {
            @Override
            public void _onNext(String randomOrderNumber) {
                mView.returnRandomOrderNumberSuccess(randomOrderNumber);
            }

            @Override
            public void _onError(String errorMessage, int errorCode) {
                super._onError(errorMessage, errorCode);
                Logger.d("访问失败" + errorMessage);
            }
        });
    }


    @Override
    public void getPlaceOrderData(Map<String, Object> map, String authorization) {
        mModel.getPlaceOrderData(map,authorization).subscribe(new ProgressObserver<String>(true,this) {
            @Override
            public void _onNext(String order) {
                mView.returnPlaceOrderData(order);
            }

            @Override
            public void _onError(String errorMessage, int errorCode) {
                super._onError(errorMessage, errorCode);
            }
        });
    }

    @Override
    public void getMarketPriceData(Map<String, Object> map) {
        mModel.getMarketPriceData(map).subscribe(new ProgressObserver<MarketPriceBean>(false,null) {
            @Override
            public void _onNext(MarketPriceBean data) {
                mView.returnMarketPriceData(data);
            }

            @Override
            public void _onError(String errorMessage, int errorCode) {
                super._onError(errorMessage, errorCode);
            }
        });
    }

    @Override
    public void getAdditionalRequirementsData(Map<String, Object> map) {
        mModel.getAdditionalRequirementsData(map).subscribe(new ProgressObserver<List<AdditionalRequirementsBean>>(false,this) {
            @Override
            public void _onNext(List<AdditionalRequirementsBean> data) {
                mView.returnAdditionalRequirementsData(data);
            }

            @Override
            public void _onError(String errorMessage, int errorCode) {
                super._onError(errorMessage, errorCode);
            }
        });
    }

    @Override
    public void getCouponsAvailableData(Map<String, Object> map) {
        mModel.getCouponsAvailableData(map).subscribe(new ProgressObserver<List<CouponAvailableBean>>(false,this) {
            @Override
            public void _onNext(List<CouponAvailableBean> data) {
                mView.returnCouponsAvailableData(data);
            }
        });
    }
}
